package com.dongnam.quanly.web.danhmuc.nhanvien;

import java.util.List;
import java.util.Map;

import javax.faces.model.ListDataModel;

import org.primefaces.model.LazyDataModel;
import org.primefaces.model.SelectableDataModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.dongnam.quanly.common.controller.NhanVienController;
import com.dongnam.quanly.common.model.NhanVien;
import com.dongnam.quanly.web.danhmuc.phongban.PhongBanBean;

import org.primefaces.model.SortOrder;

public class NhanVienModel extends LazyDataModel<NhanVien> implements SelectableDataModel<NhanVien> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * 
	 */
	private static final Logger logger = LoggerFactory.getLogger(NhanVienModel.class);

	public NhanVienModel() {
	}

	public void init() {
		int count = (int) new NhanVienController().findCountByFilters();
		setRowCount(count);

		logger.debug("init: setRowCount = {}", count);

	}

	@Override
	public List<NhanVien> load(int first, int pageSize, String sortField, SortOrder sortOrder,
			Map<String, Object> filters) {

		if (sortField == null) {
			sortField = "updateDate";
			sortOrder = SortOrder.DESCENDING;
		}

		logger.debug("load (first = {}, pageSize = {}, sortField = {}, sortOrder = {})", new Object[] { first,
				pageSize, sortField, sortOrder.toString() });
		List<NhanVien> list = new NhanVienController().findByFilters(pageSize, first / pageSize,
				SortOrder.valueOf(sortOrder.name()).toString(), sortField);

		return list;
	}

}
